//
//  ZYCAttendanceSingleDetailsHeaderView.m
//  ZDSC
//
//  Created by 张威 on 2021/10/26.
//

#import "ZYCAttendanceSingleDetailsHeaderView.h"
#import "ZYCAttendanceSingleDetailsHeaderCell.h"
#import "ZYCAttendanceSingleDetailsModel.h"

@interface ZYCAttendanceSingleDetailsHeaderView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;

@end

@implementation ZYCAttendanceSingleDetailsHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.tableView];
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
    return self;
}

- (void)setModel:(ZYCAttendanceSingleDetailsModel *)model{
    _model = model;
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCAttendanceSingleDetailsHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCAttendanceSingleDetailsHeaderCell class]) forIndexPath:indexPath];
    cell.titleString = self.dataSource[indexPath.row];
    switch (indexPath.row) {
        case 0:{
            cell.contentString = self.model.postName;
            break;
        }
        case 1:{
            cell.contentString = [NSString stringWithFormat:@"%@天",self.model.countCQ];
            break;
        }
        case 2:{
            cell.contentString = [NSString stringWithFormat:@"%@天",self.model.countXX];
            break;
        }
        default:
            break;
    }
    return cell;
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5.0f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = HEX_RGB(@"#FAFAFA");
    return headerView;
}


#pragma mark - getters

- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[@"所属岗位:",@"出勤天数:",@"休息天数:"];
    }
    return _dataSource;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ZYCAttendanceSingleDetailsHeaderCell class] forCellReuseIdentifier:NSStringFromClass([ZYCAttendanceSingleDetailsHeaderCell class])];
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
    }
    return _tableView;
}
@end
